<template>
  <div class="app-container">
    <!-- 基本信息 -->
    <div class="titleLineGreen">基本信息</div>
    <div class="info flex">
      <el-image
        v-if="info"
        class="info_avatar"
        :src="
          info.schoolPic
            ? info.schoolPic
            : require('@/assets/images/branch.png')
        "
        :preview-src-list="[info.schoolPic]"
      ></el-image>
      <div class="info_right">
        <!-- 工作站信息 -->
        <div class="info_teacherinfos">
          <div class="flex info_teacherinfo_line1">
            <div class="info_teacherinfo_line_item flex">
              <Texttooltip
                :text="info.schoolName ? info.schoolName : ''"
                width="100%"
                class="info_teacherinfo_line_item_nickname overtxt"
              >
              </Texttooltip>
            </div>
            <div
              v-preventReClick
              class="shou"
              @click.stop="handleUpdate(item)"
              style="
                font-size: 14px;
                font-weight: 400;
                line-height: 20px;
                color: #606266;
              "
            >
              <i class="el-icon-edit"></i>编辑
            </div>
            <div
              v-preventReClick
              class="shou"
              @click.stop="HandleAdmin(item)"
              style="
                margin-left: 20px;
                font-size: 14px;
                font-weight: 400;
                line-height: 20px;
                color: #606266;
              "
            >
              <i class="el-icon-user"></i>管理员设置
            </div>
          </div>
          <div class="flex info_teacherinfo_line2">
            <div class="info_teacherinfo_line_item_short overtxt">
              <Texttooltip
                :text="`门店类型: ${info.tagName ? info.tagName : '--'}`"
                :width="200"
              >
              </Texttooltip>
            </div>
            <div class="info_teacherinfo_line_item_short overtxt">
              <Texttooltip
                :text="`大区: ${info.regionName ? info.regionName : '--'}`"
                :width="200"
              >
              </Texttooltip>
            </div>
            <div class="info_teacherinfo_line_item_short overtxt">
              <Texttooltip :text="`人员: ${info.studentNum}`" :width="200">
              </Texttooltip>
            </div>
          </div>
          <div class="info_teacherinfo_line2">
            <div class="info_teacherinfo_line_item_short overtxt">
              <Texttooltip
                :text="`地址:${info.schoolArea + info.schoolAddress}`"
                :width="400"
              >
              </Texttooltip>
            </div>
          </div>
          <div class="flex info_teacherinfo_courseIntro">
            简介:
            <div class="courseIntro">
              {{ info.content ? info.content : "--" }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 详细 -->
    <div class="titleLineGreen" style="margin-top: 40px">详细</div>
    <div style="padding: 10px 0 0 10px">
      <el-tabs v-model="activeName" type="border-card">
        <!-- 课程情况 -->
        <el-tab-pane label="课程情况" name="courseDetail">
          <div style="padding: 20px">
            <el-form
              style="width: 100%"
              :model="course_queryParams"
              ref="course_queryForm"
              size="small"
              :inline="true"
              label-width="40px"
            >
              <el-form-item label="课程" prop="courseName">
                <el-input
                  v-input-restrict
                  style="width: 150px"
                  v-model="course_queryParams.courseName"
                  placeholder="请输入课程名称"
                  clearable
                  @keyup.enter.native="course_handleQuery"
                />
              </el-form-item>
              <el-form-item>
                <el-button
                  v-preventReClick
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="course_handleQuery"
                  >搜索</el-button
                >
                <el-button
                  v-preventReClick
                  icon="el-icon-refresh"
                  size="mini"
                  @click="course_resetQuery"
                  >重置</el-button
                >
              </el-form-item>
              <!-- <right-toolbar
              style="margin-top: 3px"
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar> -->
            </el-form>
            <el-table v-loading="loading" :data="courseList">
              <el-table-column
                label="课程名称"
                align="center"
                prop="courseName"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                width="120"
                label="封面"
                align="center"
                prop="coursePic"
              >
                <template slot-scope="scope">
                  <el-image
                    :src="scope.row.coursePic"
                    fit="cover"
                    :width="120"
                  />
                </template>
              </el-table-column>
              <el-table-column
                label="课时(h)"
                align="center"
                prop="studyTime"
                :show-overflow-tooltip="true"
              >
                <template slot-scope="scope">
                  {{ scope.row.studyTime ? scope.row.studyTime : "--" }}
                </template>
              </el-table-column>
              <el-table-column
                label="岗位"
                align="center"
                prop="postNames"
                :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                label="训练员"
                align="center"
                prop="trainNames"
                width="160"
              >
                <template slot-scope="scope">
                  {{ scope.row.trainNames ? scope.row.trainNames : "--" }}
                </template>
              </el-table-column>
              <el-table-column
                label="生效时间"
                align="center"
                prop="startDate"
                width="160"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.startDate }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="有效期至"
                align="center"
                prop="endDate"
                width="160"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.endDate }}</span>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              v-show="course_total > 0"
              :total="course_total"
              :page.sync="course_queryParams.pageNum"
              :limit.sync="course_queryParams.pageSize"
              @pagination="getCourseList"
            />
          </div>
        </el-tab-pane>
        <!-- 员工情况 -->
        <el-tab-pane label="员工情况" name="staffDetail">
          <userList :info="info"></userList>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 添加门店弹框 -->
    <addShop
      @refresh="getInfo()"
      :open.sync="addShop_open"
      :type="addShop_type"
      :shopId="addShop_shopId"
    ></addShop>
    <!-- 管理员设置弹框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="管理员设置"
      :visible.sync="adminListOpen"
      width="1000px"
      append-to-body
    >
      <el-button
        v-preventReClick
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAddAdmin"
        >添加管理员</el-button
      >
      <el-table
        v-loading="adminloading"
        style="margin-top: 20px"
        :data="adminList"
      >
        <el-table-column
          align="center"
          property="name"
          label="姓名"
        ></el-table-column>
        <el-table-column
          align="center"
          property="phoneNumber"
          label="账号"
        ></el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          property="postNames"
          label="岗位"
        ></el-table-column>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status == 0">启用</el-tag>
            <el-tag type="danger" v-if="scope.row.status == 1">禁用</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <!-- <el-button
              v-preventReClick
              size="mini"
              type="text"
              icon="el-icon-open"
              @click="handleAdminSwitch(scope.row)"
              >{{ scope.row.status == 0 ? "停用" : "启用" }}</el-button
            > -->
            <el-button
              v-preventReClick
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleAdminDelete(scope.row)"
              >移除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 添加编辑 管理员弹框 -->
    <addShopAdminDialog
      :open.sync="addAdminOpen"
      @refresh="getAdminList()"
      :shopObject="addAdmin_shopObject"
      :existsAdmins="adminList"
    ></addShopAdminDialog>
  </div>
</template>

<script>
import addShop from "./component/addShop";
import userList from "./component/userList";
import { getPost_school } from "@/api/school/list";
import { orderCourseList } from "@/api/course/course";
import addShopAdminDialog from "./component/addShopAdmin";
import {
  schoolManagerlist,
  addPost_changeStatus,
  delPost_student,
  unbindSchoolAdmin,
} from "@/api/schoolOrganization/student";
export default {
  dicts: ["sys_normal_disable", "sys_user_sex"],
  components: { userList, addShop, addShopAdminDialog },
  props: {},
  data() {
    return {
      item: {},
      activeName: "courseDetail",
      // 遮罩层
      loading: false,
      showSearch: false,
      course_total: 0,
      courseList: [],
      // 查询参数
      course_queryParams: {
        pageNum: 1,
        pageSize: 10,

        courseName: undefined,
      },
      info: {},

      addShop_open: false,
      addShop_type: 1,
      addShop_shopId: null,

      adminList: [],
      adminListOpen: false,
      editAdminId: "",
      editBranchId: "",
      addAdminOpen: false,
      addAdmin_shopObject: {},
      adminloading: false,
    };
  },
  watch: {},
  methods: {
    /** 修改按钮操作 */
    handleUpdate() {
      this.addShop_open = true;
      this.addShop_type = 2;
      this.addShop_shopId = this.$route.query.shopId;
    },
    /*  管理员设置*/
    async HandleAdmin() {
      this.addAdmin_shopObject = {
        schoolId: this.$route.query.shopId,
        schoolName: this.info.schoolName,
      };
      this.adminListOpen = true;
      this.getAdminList();
    },
    /* 获取门店管理员列表 */
    async getAdminList() {
      this.adminloading = true;
      let res = await schoolManagerlist({
        schoolIds: this.addAdmin_shopObject.schoolId,
      });
      this.adminList = res.data ;
      this.adminloading = false;
    },
    /* 添加管理员 */
    handleAddAdmin() {
      this.addAdminOpen = true;
    },
    // 删除管理员
    async handleAdminDelete(row) {
      this.$confirm(
        `确认移除管理员【${row.name}】吗？移除后该账号不可登录门店管理端`,
        `移除管理员确认`,
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          unbindSchoolAdmin(this.addAdmin_shopObject.schoolId, row.userId).then(
            (res) => {
              this.$modal.msgSuccess("移除管理员成功");
              this.open = false;
              this.getAdminList();
            }
          );
        })
        .catch(() => {});
    },
    // 停用 启用管理员
    handleAdminSwitch(row) {
      this.$confirm(
        `确定${row.status == "0" ? "停用" : "启用"}【${row.name}】吗?${
          row.status == "0" ? "停用后该账号不可登录使用！" : ""
        }`,
        `${row.status == "0" ? "停用提示" : "启用提示"}`,
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          let formData = new FormData();
          formData.append("studentIds", row.studentId);
          formData.append("status", row.status == 0 ? 1 : 0);
          addPost_changeStatus(formData).then((response) => {
            this.$modal.msgSuccess(
              `${row.status == "0" ? "停用" : "启用"}成功`
            );
            this.open = false;
            this.getAdminList();
          });
        })
        .catch(() => {});
    },
    async getCourseList() {
      console.log("获取课程列表");
      try {
        this.loading = true;
        this.course_queryParams.schoolIds = this.$route.query.shopId;
        let res = await orderCourseList(this.course_queryParams);
        this.courseList = res.rows;
        this.course_total = res.total;
      } finally {
        this.loading = false;
      }
    },
    /* 查询工作站详细信息 */
    async getInfo() {
      let res = await getPost_school(this.$route.query.shopId);
      this.info = res.data;
    },
    course_handleQuery() {
      this.course_queryParams.pageNum = 1;
      this.getCourseList();
    },
    /** 重置按钮操作 */
    course_resetQuery() {
      this.resetForm("course_queryForm");
      this.course_handleQuery();
    },
  },
  created() {},
  mounted() {
    this.getInfo();
    this.getCourseList();
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-tabs--border-card > .el-tabs__content {
  padding: 0;
}
.info.flex {
  width: 100%;
  margin: 23px 0 0 0;
  .info_avatar {
    width: 120px;
    height: 64px;
    box-sizing: border-box;
    border: 1px solid rgba(229, 229, 229, 1);
    margin: 0 24px 0 10px;
  }

  .info_right {
    flex: 1;
    .info_teacherinfos {
      .info_teacherinfo_line1 {
        margin-top: 3px;
      }
      .info_teacherinfo_line2 {
      }
      .info_teacherinfo_associateACourse {
        margin-top: 14px;
        font-size: 14px;
        font-weight: 400;
        line-height: 24px;
        color: rgba(96, 98, 102, 1);
        .associateACourses {
          margin-left: 6px;
          width: 705px;
          .associateACourses_item {
            margin: 0 0 8px 8px;
            padding: 0 12px;
            font-size: 14px;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            height: 24px;
            opacity: 1;
            border-radius: 2px;
            line-height: 24px;
            background: rgba(39, 196, 120, 0.8);
          }
        }
      }
      .info_teacherinfo_courseIntro {
        margin-top: 8px;
        font-size: 14px;
        font-weight: 400;
        line-height: 20px;
        color: rgba(96, 98, 102, 1);
        .courseIntro {
          word-wrap: break-word;
          width: 700px;
        }
      }
      .info_teacherinfo_line_item_short {
        margin-top: 8px;
        box-sizing: border-box;
        padding-right: 25px;
        width: 200px;
        font-size: 14px;
        font-weight: 400;
        line-height: 20px;
        color: rgba(96, 98, 102, 1);
      }
      .info_teacherinfo_line_item {
        box-sizing: border-box;
        padding-right: 25px;
        max-width: 276px;
        font-size: 14px;
        font-weight: 400;
        line-height: 20px;
        color: rgba(96, 98, 102, 1);
        .info_teacherinfo_line_item_nickname {
          font-size: 18px;
          font-weight: 600;
          line-height: 20px;
          color: rgba(51, 51, 51, 1);
          max-width: 227px;
        }
        .sex {
          margin: 5px 0 0 5px;
          width: 12px;
          height: 12px;
        }
      }
    }

    .info_dataCards {
      margin-top: 22px;
      .info_dataCard {
        height: 112px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 0px 12px rgba(99, 99, 99, 0.14);
        box-sizing: border-box;
        padding: 16px 0 0 20px;
        .info_dataCard_topLine.flex {
          .info_dataCard_topLine_point {
            margin: 5px 8px 0 0;
            width: 10px;
            height: 10px;
            border-radius: 5px;
          }
          .info_dataCard_topLine_lable {
            font-size: 14px;
            font-weight: 600;
            line-height: 20px;
            color: rgba(51, 51, 51, 1);
            span {
              margin: 4px 0 0 0;
              font-size: 10px;
              font-weight: 400;
              line-height: 14px;
              color: rgba(51, 51, 51, 1);
            }
          }
        }
        .info_dataCard_dateLine2 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 60px !important;
          }
        }
        .info_dataCard_dateLine1 {
          .info_dataCard_dateLine_item:last-of-type {
            width: 92px !important;
          }
        }
        .info_dataCard_dateLine.flex {
          margin-top: 20px;
          .info_dataCard_dateLine_item {
            width: 100px;
            .info_dataCard_dateLine_item_lable {
              font-size: 12px;
              font-weight: 400;
              line-height: 17px;
              color: rgba(153, 153, 153, 1);
            }

            .info_dataCard_dateLine_item_value {
              margin-top: 4px;
              font-size: 18px;
              font-weight: 600;
              line-height: 25px;
              color: rgba(238, 62, 62, 1);
              span {
                margin: 4px 0 0 0;
                font-size: 12px;
                font-weight: 400;
                line-height: 16px;
                color: rgba(51, 51, 51, 1);
              }
            }
          }
        }
      }
    }
  }
}
</style>
